// pages/follow/folquery/folquery.js
// var list = require("../../../followdata.js");
var net = require("../../../utils/net.js");
var gd = getApp().globalData;
var posting = false;
var dialog=null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    t1:"日期",
    name: "",
    list: [],
    keyword: "",
    search_day:"",
    days:0,
    shop_id: gd.shop_id,
    member_ship_id: gd.id,
    search_type:4,
    datestart: "",
    dataend: ""
  },
  query(){
    this.getData();
  },
  getData(){
    if (posting)return;
    posting = true;
    var that =this;
    var td = that.data;
    wx.showLoading({})
    net.request({
      url:'/Search',
      data:{
        keywords: td.keyword,
        search_day: that.data.datestart,
        shop_id: gd.shop_id,
        member_ship_id: gd.id,
        search_type: td.search_type,
      },success(res){
        var dt = res.data;
        if(dt.flag){
          var list = dt.data
          for(let i =0;i<list.length;++i)
            list[i].create_time = list[i].create_time.substring(0,10);
          that.setData({
            list:list
          })
        }else{
          that.setData({
            list: []
          })
          dialog.showDialog({
            msg: dt.msg
          })
        }
      },complete(){
        wx.hideLoading()
        posting = false;
      }
    })
  },
  cancelDate(){
    console.log("cancelDate");
    this.setData({
      search_day:""
    })
  },
  startDateChange(e){
    this.setData({
      datestart: e.detail.value//.substring(2).replace(/\-/g, "/")
    })
  }, endDateChange(e) {
    this.setData({
      dateend: e.detail.value.substring(2).replace(/\-/g,"/")
    })
  },
  input(e) {
    var value = e.detail.value + "";
    var key = e.currentTarget.id + "";
    this.setData({
      [key]: value,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var type = options.type||1;
    var title="MC跟进查询";
    var t1 = "跟进日期";
    if(type==2){
      title = "MC预约查询";t1 = "预约日期";
    }
    this.setData({
      search_type: type,
      t1: t1
    })
    wx.setNavigationBarTitle({
      title: title,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    dialog = this.selectComponent("#dialog");
    this.getData();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      name: wx.getStorageSync("name")
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    // this.setData({
    //   list: []
    // })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})